Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(billing): return service/asset usage for current period TASK-1327 #5326

Merged

Conversation

jamesrkiger
Copy link
Contributor

@jamesrkiger jamesrkiger commented Dec 4, 2024

📣 Summary

Update asset and service usage code to return only a single set of data for the current billing cycle, regardless of whether that cycle is monthly or yearly and adjust frontend accordingly.

📖 Description

Currently, the ServiceUsageSerializer and AssetUsageSerializer return usage information calculated according to a monthly billing cycle and a yearly billing cycle, regardless of what kind of billing cycle a user is actually subscribed to. So if a user is on a monthly plan, we make up a hypothetical yearly cycle and return data for that in addition to the actual monthly cycle they are on. The frontend, in turn, selects the correct cycle information to display based on a separate request fetching the user’s subscription information. The hypothetical cycle is never displayed and doesn’t seem to be used for anything at all.

This PR merges the functionality of the get_monthly_billing_dates() and get_yearly_billing_dates() utils into a single function that, once it determines which cycle an account is on, returns the relevant period_start and period_end dates.

👀 Preview steps

For frontend preview:

  1. Create a new user on a Stripe-enabled instance

  2. Navigate to usage page. Observe that user is on community plan with start date corresponding to account creation date. Displayed usage period should correspond to either first day of this month or last day of previous month (most likely the latter, though it currently depends on one’s timezone) and the last day of this month.

  3. Purchase a monthly plan and sync djstripe Subscriptions, navigate to usage page. Observe that start date is still account creation date. Displayed usage period should now correspond to start date and one month after start date.

  4. Cancel plan as the user, then cancel the plan via Stripe (or ask someone to do this), and sync subscriptions. Visit
    usage page and observe dates have not changed (because your community plan dates now correspond to date of cancellation and one month later).

  5. Sign up for a yearly plan and sync subscriptions. Visit usage page and observe that start date remains the same, while displayed usage period ends a year from today.

…od, regardless of whether it is monthly or yearly and update tests accordingly
@jamesrkiger jamesrkiger marked this pull request as draft December 4, 2024 18:26
@jamesrkiger jamesrkiger marked this pull request as ready for review December 12, 2024 18:14
@jamesrkiger jamesrkiger requested a review from Guitlle December 12, 2024 18:14
@jamesrkiger jamesrkiger self-assigned this Dec 12, 2024
@jamesrkiger jamesrkiger changed the title fix(billing): return service/asset usage for current period TASK 1327 fix(billing): return service/asset usage for current period TASK-1327 Dec 12, 2024
…ASK-1328 (#5356)

### 📣 Summary
Adjusts frontend types and handling of data service/asset usage data
according to the changes in #5326.

### 📖 Description
Previously, the ServiceUsageSerializer and AssetUsageSerializer returned
usage information calculated according to a monthly billing cycle and a
yearly billing cycle, regardless of what kind of billing cycle a user
was actually subscribed to. So if a user was on a monthly plan, we made
up a hypothetical yearly cycle and returned data for that in addition to
the actual monthly cycle they are on. The frontend, in turn, selected
the correct cycle information to display based on a separate request
fetching the user’s subscription information. The hypothetical periods
have been removed from the backend, which now returns only data for
"current_period". This PR updates the frontend to handle this new data
format.


### 👀 Preview steps
1. Create a new user on a Stripe-enabled instance

2. Navigate to usage page. Observe that user is on community plan with
start date corresponding to account creation date. Displayed usage
period should correspond to either first day of this month or last day
of previous month (most likely the latter, though it currently depends
on one’s timezone) and the last day of this month.

3. Purchase a monthly plan and sync djstripe Subscriptions, navigate to
usage page. Observe that start date is still account creation date.
Displayed usage period should now correspond to start date and one month
after start date.

4. Cancel plan as the user, then cancel the plan via Stripe (or ask
someone to do this), and sync subscriptions. Visit
usage page and observe dates have not changed (because your community
plan dates now correspond to date of cancellation and one month later).

5. Sign up for a yearly plan and sync subscriptions. Visit usage page
and observe that start date remains the same, while displayed usage
period ends a year from today.
@jamesrkiger jamesrkiger merged commit 4e3e5fd into main Dec 16, 2024
7 checks passed
@jamesrkiger jamesrkiger deleted the task-1327-return-only-relevant-cycle-for-service-usage branch December 16, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants